import { app, BrowserWindow } from 'electron'
import { createWindow } from './main/window';
import { registerEvents } from './main/events';

// const require = createRequire(import.meta.url)

let mainWindow: BrowserWindow | any;

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', (event: any) => {
  event.preventDefault();

  if (process.platform !== 'darwin') {
    app.quit()
    mainWindow = null
  }
});

// 在应用退出前销毁托盘
// app.on('before-quit', () => {
//   if (tray) {
//     tray.destroy();
//     tray = null;
//   }
// });

app.on('activate', () => {
  // On OS X it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow()
  }
});

app.whenReady().then(() => {
  mainWindow = createWindow();
  registerEvents(mainWindow);
});



